package com.cencat.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 用户权限关联实体类
 * @author cencat
 * @since 2024-01-01
 */
@Entity
@Table(name = "sys_user_permission")
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "用户权限关联")
public class UserPermission {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    @Schema(description = "主键ID")
    private Long id;

    @Column(name = "user_id", nullable = false)
    @Schema(description = "用户ID")
    private Long userId;

    @Column(name = "permission_id", nullable = false)
    @Schema(description = "权限ID")
    private Long permissionId;

    @Column(name = "tenant_id")
    @Schema(description = "租户ID")
    private Long tenantId;

    @Column(name = "granted_by")
    @Schema(description = "授权人ID")
    private Long grantedBy;

    @Column(name = "granted_time")
    @Schema(description = "授权时间")
    private LocalDateTime grantedTime;

    @Column(name = "expire_time")
    @Schema(description = "权限过期时间")
    private LocalDateTime expireTime;

    @Column(name = "status", nullable = false)
    @Schema(description = "状态：1-有效，0-无效")
    private Integer status = 1;

    @Column(name = "remark")
    @Schema(description = "备注")
    private String remark;

    @Column(name = "create_time", nullable = false, updatable = false)
    @TableField(fill = FieldFill.INSERT)
    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Column(name = "update_time")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    @Column(name = "create_by")
    @Schema(description = "创建人")
    private Long createBy;

    @Column(name = "update_by")
    @Schema(description = "更新人")
    private Long updateBy;

    @Column(name = "deleted", nullable = false)
    @TableLogic
    @Schema(description = "删除标记：0-未删除，1-已删除")
    private Integer deleted = 0;
}